package com.cusc.module_login.mvvm.ui;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.cusc.module_login.R;
import com.tcgroup.phone.base_core.framework.mvvm.AbstractActivity;
import com.tcgroup.phone.base_core.store.MmkvStore;
import com.tcgroup.phone.base_core.store.StoreKey;
import com.tcgroup.phone.base_core.utils.DpPxUtil;
import com.to.aboomy.banner.Banner;
import com.to.aboomy.banner.HolderCreator;
import com.to.aboomy.banner.IndicatorView;
import com.to.aboomy.banner.ScaleInTransformer;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者: wangfei
 * 创建时期: 2020/3/25.
 * 包名: com.cusc.module_login
 * 类名: OSAndroidMvvm
 */
public class ChoosePlatformsActivity extends AbstractActivity implements HolderCreator {

    Banner banner;
    public final List<Integer> IMAGES = new ArrayList();

    @Override
    public void onRetryBtnClick() {

    }

    @Override
    public void onBackPressedClick() {
        Intent intent = new Intent(this,LoginActivity.class);
        startActivity(intent);
        finish();
    }

    @Override
    public int onBindLayout() {
        return R.layout.act_choose_platform;
    }

    @Override
    public Object bindLoadSir() {
        return this;
    }


    @Override
    public void initContentView() {
        super.initContentView();
        banner = findViewById(R.id.banner);
        IMAGES.add(R.drawable.login_image_01);
        IMAGES.add(R.drawable.login_image_02);
        banner.setHolderCreator(this)
                .setAutoTurningTime(3000)
                .setIndicator(new IndicatorView(this)
                        .setIndicatorColor(Color.GRAY)
                        .setIndicatorStyle(IndicatorView.IndicatorStyle.INDICATOR_CIRCLE_RECT)
                        .setIndicatorSelectorColor(Color.RED), false)
                .setPageMargin(DpPxUtil.Dp2Px(this,20), DpPxUtil.Dp2Px(this, 10))
                .setPageTransformer(true, new ScaleInTransformer())
                .setPages(IMAGES);
    }

    @Override
    public View createView(Context context, int index, Object o) {
        View view = View.inflate(context, R.layout.act_banner_item, null);
        ImageView image = view.findViewById(R.id.img);
        Glide.with(image).load(o).apply(new RequestOptions().transform(new RoundedCorners(DpPxUtil.Dp2Px(this, 10)))).into(image);
        image.setOnClickListener(v ->{
            switch (index){
                case 0:
                    MmkvStore.getInstance().getMmkv().encode(StoreKey.Module_Login.Module_Id,"02");
                    MmkvStore.getInstance().removeValueForKey(StoreKey.Module_Login.Module_List_01);
                    startActivity(new Intent(this, FunctionActivity.class));
                    finish();
                    break;
                case 1:
                    MmkvStore.getInstance().getMmkv().encode(StoreKey.Module_Login.Module_Id,"01");
                    break;
            }
        });
        return view;
    }
}
